package cn.shiva.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;

/**
 * @author shiva   2021/10/15 21:44
 */
@Slf4j
@Configuration
public class StreamInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        BufferedReader br = request.getReader();
        String str2;
        StringBuilder wholeStr = new StringBuilder();
        while ((str2 = br.readLine()) != null) {
            wholeStr.append(str2);
        }
        log.info("【请求链接】：{}，【请求参数】：{}", request.getRequestURI(), wholeStr.toString());
        return true;
    }
}
